import "element-plus/theme-chalk/index.css";
import "element-plus/theme-chalk/dark/css-vars.css";
import "/@//assets/css/jeesdp.css";

import dayjs from "dayjs";
import cookie from "js-cookie";
import ElementPlus from "element-plus";
import zhCn from "element-plus/dist/locale/zh-cn";
import * as icons from "@element-plus/icons-vue";

import {JeesdpForm, JeesdpHttp as axios, JeesdpIcon, JeesdpList, JeesdpTable} from "@jeesdp/components";

import Datagrid from "/@//components/datagrid";
import AsideMenu from "/@//components/layout/asidemenu";


import utils from "/@//components/utlis";
import locale from "/@//components/locale";
import buttons from "/@//components/buttons";
import validators from "/@//components/validators";
import formatters from "/@//components/formatters";

import hasPermissions from "/@//directive/hasPermissions";
import {beforeEach, router} from "/@//components/router";

export default {
    install: (app, options) => {
        app.use(router);
        app.use(locale);
        app.use(ElementPlus, {locale: zhCn,});
        app.use(JeesdpIcon);
        app.use(JeesdpForm);
        app.use(JeesdpTable);

        app.config.globalProperties.$axios = axios;
        app.config.globalProperties.$cookie = cookie;
        app.config.globalProperties.$dayjs = dayjs;
        app.config.globalProperties.$utils = utils;

        app.component(JeesdpList.name, JeesdpList);
        /*app.component(JsonEditor.name, JsonEditor);*/
        app.component(AsideMenu.name, AsideMenu);
        app.component(Datagrid.name, Datagrid);
        for (let name in icons) {
            app.component(name, icons[name]);
        }

        app.directive("has-permissions", hasPermissions);
        router.beforeEach((to, from, next) => {
            beforeEach(to, from, next);
        });

        app.mixin({
            data() {
                return {
                    buttons: buttons,
                    validators: validators,
                    formatters: formatters
                }
            },
            methods: {
                demo(scope) {
                    return `${dayjs(scope.row[0]).format('YYYY-MM-DD HH:mm:ss')} - ${dayjs(scope.row[1]).format('YYYY-MM-DD HH:mm:ss')}`;
                }
            }
        });
    }
}

